﻿// <copyright file="BFSourceFilesParser.cs" company="Horiba Medical">
//     Copyright (c) Horiba Medical. All rights reserved.
// </copyright>
// <summary>
//     Provides a source files parser for BF project files.
// </summary>

namespace DoxyOutParser.CodeCheck
{
	using System.Collections.Generic;
	using System.Collections.ObjectModel;
	using System.Xml;
	using System.Xml.XPath;

	/// <summary>
	/// Parses a BF project file to extract the C source files specified within it.
	/// </summary>
	public class BFSourceFilesParser : ISourceFilesParser
	{
		/// <summary>
		/// The file which needs parsing.
		/// </summary>
		private string blackfinProjectFile;

		/// <summary>
		/// Initializes a new instance of the BFSourceFilesParser class.
		/// </summary>
		/// <param name="projectFile">Path to the BF project file which needs parsing.</param>
		public BFSourceFilesParser(string projectFile)
		{
			// TODO Check the value of string and eventually check if exist or not.
			this.blackfinProjectFile = projectFile;
		}

		#region ISourceFilesParser Members

		/// <summary>
		/// Gets the list of source files specified in the project file.
		/// </summary>
		/// <value>No set available.</value>
		/// <returns>The generated list.</returns>
		public List<string> SourceFilesList
		{
			get
			{
				List<string> sourceFilesList = new List<string>();

				// Using Xpath Document
				XPathDocument blackfinProject = new XPathDocument(this.blackfinProjectFile);
				XPathNavigator blackfinProjectNavigator = blackfinProject.CreateNavigator();

				XPathNodeIterator fileListIterator = (XPathNodeIterator)blackfinProjectNavigator.Select("//file[contains(@name,'.c')]");

				foreach (XPathNavigator currentNode in fileListIterator)
				{
					string sourceName = currentNode.GetAttribute("name", string.Empty);
					sourceFilesList.Add(sourceName);
				}

				return sourceFilesList;
			}
		}

		#endregion
	}
}
